package cn.vcjf.weapp.api.goods.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.vcjf.weapp.common.web.TableResult;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import cn.vcjf.weapp.api.goods.entity.GoodsGroup;
import cn.vcjf.weapp.api.goods.service.GoodsGroupService;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  商品规格组合,不同组合,不同价格
 * </p>
 *
 * @author zhengzihang
 * @since 2018-09-25
 */
@Controller
@RequestMapping("/goods/goodsGroup")
public class GoodsGroupController {
     @Resource
     private GoodsGroupService  goodsGroupService;

     @RequestMapping("/addGoodsGroup")
     @ResponseBody
     public TableResult addGoodsGroup(GoodsGroup goodsGroup){
         goodsGroup.preInsert();
         boolean b = goodsGroupService.insert(goodsGroup);
         return TableResult.Result(b);
     }

	/**
	 * 添加库存
	 * @param goodsGroup
	 * @return
	 */
     @RequestMapping("/addGoodsGroupRepertory")
     @ResponseBody
     public TableResult updateGoodsGroup(GoodsGroup goodsGroup){
         goodsGroup.preUpdate();
        boolean b = goodsGroupService.updateById(goodsGroup);
         return TableResult.Result(b);
     }

    /**
     * 获取组合规格的商品的价格和库存
     * @param goodsGroup
     * @return
     */
     @RequestMapping("/selectRepertoryForUpdate")
     @ResponseBody
     public TableResult selectRepertoryForUpdate(GoodsGroup goodsGroup){

        GoodsGroup result = goodsGroupService.selectRepertoryForUpdate(goodsGroup);

		return TableResult.OKResult(result);
     }

    /**
     * 获取组合规格的商品的价格和库存
     * @param goodsGroup
     * @return
     */
     @RequestMapping("/findGoodsGroup")
     @ResponseBody
     public TableResult findGoodsGroupOne(GoodsGroup goodsGroup){

        EntityWrapper<GoodsGroup> wrapper = new EntityWrapper<GoodsGroup>();

        wrapper.eq("sysUserId",goodsGroup.getSysUserId());
        wrapper.eq("goodsId",goodsGroup.getGoodsId());
        wrapper.eq("proId",goodsGroup.getProId());

        GoodsGroup result = goodsGroupService.selectOne(wrapper);

		return TableResult.OKResult(result);
     }

     @RequestMapping("/findGoodsGroupList")
     @ResponseBody
     public TableResult findGoodsGroupList(GoodsGroup goodsGroup){

        EntityWrapper<GoodsGroup> wrapper = new EntityWrapper<GoodsGroup>();

		if(goodsGroup.getId()!=null){
            wrapper.eq("id",goodsGroup.getId());
        }
        //Todo

        Page<GoodsGroup> page = goodsGroup.getPageInfo();

        page = goodsGroupService.selectPage(page,wrapper);

		return TableResult.OKResult(page);

     }

     @RequestMapping("/deleteGoodsGroup")
     @ResponseBody
     public TableResult deleteGoodsGroup(GoodsGroup goodsGroup){
        goodsGroup.preUpdate();
        boolean b = goodsGroupService.deleteById(goodsGroup.getId());
        return TableResult.Result(b);
     }

}
